package site.yunnong.atvris.portal.spider.haokan;

import org.springframework.stereotype.Service;
import site.yunnong.atvris.common.utils.DateUtils;
import site.yunnong.atvris.dao.domain.Video;
import site.yunnong.atvris.dao.mapper.VideoMapper;
import site.yunnong.atvris.portal.spider.AbstractVideoObject;
import site.yunnong.atvris.portal.spider.VideoImportService;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author zjh
 * @date 2021/9/2 22:52
 */
@Service
public class HaokanVideoImportServiceImpl implements VideoImportService {
    
    @Resource
    private VideoMapper videoMapper;
    
    @Override
    public void importVideo(AbstractVideoObject videoObject) {
        System.out.println("insert video, video.title: " + ((HaokanVideo) videoObject).getTitle());
        String pid = ((HaokanVideo) videoObject).getPid();
        Video video = Video.builder().uuid(SYS_UID)
                .userAvatar(SYS_USER_AVATAR)
                .userNickname(SYS_USER_NICKNAME)
                .pid(Long.valueOf(pid))
                .partitionName(((HaokanVideo) videoObject).getPartitionName())
                .level(0)
                .status(1)
                .cover(((HaokanVideo) videoObject).getCover())
                .videoTime(DateUtils.covertDurationToSecond(((HaokanVideo) videoObject).getDuration()))
                .url(((HaokanVideo) videoObject).getUrl())
                .seriesNum(1)
                .title(((HaokanVideo) videoObject).getTitle())
                .rePrintPower(1)
                .fromUrl(((HaokanVideo) videoObject).getUrl())
                .remark(((HaokanVideo) videoObject).getTitle())
                .source(((HaokanVideo) videoObject).getSource())
                .uploadTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        videoMapper.insertSelective(video);
        System.out.println("insert video, video.title: " + ((HaokanVideo) videoObject).getTitle() + "SUCCESS");
    }
}
